package jp.co.cos.ittrick.channel.controller.Information;

import java.util.List;

import jp.co.cos.ittrick.channel.Constants;
import jp.co.cos.ittrick.channel.model.ApplicationModel;
import jp.co.cos.ittrick.channel.model.ChannelModel;
import jp.co.cos.ittrick.channel.model.PageModel;
import jp.co.cos.ittrick.channel.service.ApplicationService;
import jp.co.cos.ittrick.channel.service.ChannelService;
import jp.co.cos.ittrick.channel.service.PageService;
import jp.co.cos.ittrick.channel.util.Utility;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;

public class RuleController extends Controller {

    private ApplicationService applicationService;
    private ChannelService channelService;
    private PageService pageService;

    public RuleController() {
        channelService = new ChannelService();
        applicationService = new ApplicationService();
        pageService = new PageService();
    }

    @Override
    public Navigation run() throws Exception {

        ApplicationModel applicationModel = applicationService.getApplicationModel();
        requestScope("applicationModel", applicationModel);

        List<ChannelModel> channelList = channelService.getAll();
        requestScope("channelList", channelList);

        // new 記事
        List<PageModel> newPageList = pageService.getPageListOfLimit(0, Constants.PAGE_ARTICLE_LIST_LIMIT);
        requestScope("newPageList", newPageList);


        // スマートフォンの場合
        if(Utility.isSmartPhone(request)) {
            return forward("/sp/Information/rule.jsp");
        }

        return forward("rule.jsp");
    }
}
